﻿using FollowMe.Services;
using FollowMe.Services.Request;
using Microsoft.Practices.Unity;
using System;
using System.Web.Http;

/**
 * FollowMe Server
 * UWRF CS425 & CS343 Project Fall 2014
 * Adam Drews
 *   email adam.drews@my.uwrf.edu
 * Tyler Johnson
 *   email tyler.johnson@my.uwrf.edu
 * Nicholas Thorp
 *   email nicholas.thorp@my.uwrf.edu
 */
namespace FollowMe.API.Controllers
{
    /// <summary>
    /// Member (of follow me services) related API functions
    /// </summary>
    [AllowAnonymous]
    [RoutePrefix("api/Member")]
    public class MemberController : ApiController
    {
        /// <summary>
        /// The _services
        /// </summary>
        private IFollowMeService _services;

        /// <summary>
        /// Initializes a new instance of the <see cref="MemberController"/> class.
        /// </summary>
        public MemberController()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="MemberController"/> class.
        /// </summary>
        /// <param name="services">The follow me services.</param>
        [InjectionConstructor]
        public MemberController(FollowMeService services)
        {
            _services = services;
        }

       //GET api/Member/AllInfo
        /// <summary>
        /// Alls the information.
        /// </summary>
        /// <param name="memberId">The member identifier.</param>
        /// <returns>A MemberView on success</returns>
        [Route("AllInfo", Name= "AllInfo")]
        [System.Web.Http.AcceptVerbs("GET")]
        [System.Web.Http.HttpGet]
        [AllowAnonymous]
        public IHttpActionResult AllInfo(string memberId)
        {
            if (memberId == null) { return BadRequest("null"); }
            Guid memberGuid;
            memberId = memberId.Replace("(", "").Replace("{", "").Replace("}", "").Replace(")", "").Replace("-", "");
            if (!Guid.TryParseExact(memberId, "N", out memberGuid))
            {
                return BadRequest("Bad GUID");
            }
            FindMemberInfoRequest member = new FindMemberInfoRequest
            {
                memberid = memberGuid
            };

            return Ok(_services.findMemberInfo(member));
        }
    }
}
